import 'package:flutter/material.dart';

import '../../../utils/http.dart';
import '../../../utils/toast.dart';

class ToBeGetPage extends StatefulWidget {
  const ToBeGetPage({super.key});

  @override
  State<ToBeGetPage> createState() => _ToBeGetPageState();
}

class _ToBeGetPageState extends State<ToBeGetPage> {
  List data = [];

  getData() async {
    var res = await http.get('/driver/tasks/list', params: {
      "page": 1,
      "pageSize": 10,
      "status": 1,
    });
    if (res['code'] != 200) return ToastUtil.showError('获取数据失败');
    setState(() {
      data = res['data']['items'];
    });
  }

  @override
  void initState() {
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
            alignment: Alignment.topCenter,
            height: MediaQuery.of(context).size.height,
            padding: const EdgeInsets.all(10),
            color: const Color.fromARGB(255, 244, 243, 243),
            child: data.isEmpty
                ? Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Image.asset('assets/task/ic_not_found.png'),
                      const SizedBox(height: 10),
                      const Text('无待提货物',
                          style: TextStyle(fontSize: 16, color: Colors.grey))
                    ],
                  )
                : ListView(
                    shrinkWrap: true,
                    children: data.map((item) {
                      return Container(
                          alignment: Alignment.topCenter,
                          margin: EdgeInsets.all(5),
                          padding: EdgeInsets.all(20),
                          height: 240,
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(20)),
                          child: Column(children: [
                            Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('任务编号：${item['transportTaskId']}',
                                      style: TextStyle(
                                          fontSize: 16,
                                          fontWeight: FontWeight.bold)),
                                ]),
                            const SizedBox(height: 10),
                            Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  Column(
                                    children: [
                                      Container(
                                        alignment: Alignment.center,
                                        padding: const EdgeInsets.all(5),
                                        decoration: const BoxDecoration(
                                          //背景颜色
                                          color: Colors.black,
                                          //圆角半径
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(18.0)),
                                        ),
                                        child: const Text('起',
                                            style:
                                                TextStyle(color: Colors.white)),
                                      ),
                                      //垂直分割线
                                      SizedBox(
                                        width: 1,
                                        height: 20,
                                        child: DecoratedBox(
                                          decoration: BoxDecoration(
                                              color: const Color.fromARGB(
                                                  255, 0, 250, 250)),
                                        ),
                                      ),
                                      Container(
                                        alignment: Alignment.center,
                                        padding: const EdgeInsets.all(5),
                                        decoration: const BoxDecoration(
                                          //背景颜色
                                          color: Colors.red,
                                          //圆角半径
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(18.0)),
                                        ),
                                        child: const Text('止',
                                            style:
                                                TextStyle(color: Colors.white)),
                                      ),
                                    ],
                                  ),
                                  const SizedBox(width: 10),
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Text(
                                        item['startAddress'],
                                        style: TextStyle(
                                            fontSize: 16,
                                            fontWeight: FontWeight.bold,
                                            color: Colors.grey,
                                            overflow: TextOverflow.ellipsis),
                                      ),
                                      const SizedBox(height: 30),
                                      Text(
                                        item['endAddress'],
                                        style: TextStyle(
                                            fontSize: 16,
                                            fontWeight: FontWeight.bold,
                                            color: Colors.grey,
                                            overflow: TextOverflow.ellipsis),
                                      )
                                    ],
                                  )
                                ]),
                            const SizedBox(height: 10),
                            SizedBox(
                              width: MediaQuery.of(context).size.height * 0.8,
                              height: 1,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                    color: const Color.fromARGB(
                                        255, 239, 241, 241)),
                              ),
                            ),
                            Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Text('提货时间',
                                            style: TextStyle(
                                                fontSize: 16,
                                                color: Colors.grey)),
                                        Text(item['planDepartureTime'],
                                            style: TextStyle(
                                                fontSize: 14,
                                                color: Colors.black))
                                      ]),
                                  Container(
                                    margin: const EdgeInsets.all(20),
                                    width: 80,
                                    height: 30,
                                    child: ElevatedButton(
                                        style: ElevatedButton.styleFrom(
                                          backgroundColor: const Color.fromARGB(
                                              255, 255, 0, 0),
                                          shape: RoundedRectangleBorder(
                                              borderRadius:
                                                  BorderRadius.circular(20)),
                                        ),
                                        onPressed:
                                            item['enablePickUp'] ? () {} : null,
                                        child: const Text(
                                          '提货',
                                          style: TextStyle(color: Colors.white),
                                        )),
                                  )
                                ])
                          ]));
                    }).toList())));
  }
}
